<%@ page contentType="text/html;charset=GB2312" language="java" import="java.sql.*" errorPage=""%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
    <title>留言板</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>

<%!  Connection con;//定义数据库连接对象 %>
<%!  ResultSet rs;//定义结果集对象 %>
<%!  Statement stm;//定义SQL语句对象 %>
<%!  String sql; %>

<body bgcolor="#ffffff">
<div align="center"><font color="#000000" size="5">留言板 </font> </div>
<table width="75%" border="1" cellspacing="1" cellpadding="1" align="center">

    <tr>
        <td width=12% align=center>姓名</td>
        <td width=12% align=center>性别</td>
        <td width=12% align=center>年龄</td>
        <td width=52% align=center>留言</td>
        <td width=6% align=center>修改</td>
        <td width=6% align=center>删除</td>
    </tr>

    <%
    //连接数据库
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    }catch(ClassNotFoundException e){}
    try{
    con = DriverManager.getConnection("jdbc:odbc:Northwind","","");
    stm = con.createStatement();
    sql="select * from LeaveMessage order by Id DESC";
    rs = stm.executeQuery(sql);
    while(rs.next()){
    %>

    <tr>
        <td width=12% align=center><%=rs.getString("Username" )%></td>
        <td width=12% align=center><%=rs.getString("Sex")%></td>
        <td width=12% align=center><%=rs.getString("Age")%></td>
        <td width=52% align=center><%=rs.getString("Matter")%></td>
        <td width=6% align=center><input type="button" value="修改" onclick="javascript:location.href='change.jsp'"></td>
        <td width=6% align=center><input type="button" value="删除"></td>
    </tr>

    <%
    //关闭数据库连接
    }
    rs.close();
    stm.close();
    con.close();
    }
    catch(Exception e){
    out.println(e);
    }
    %>
</table>
<div align="center"><a href='insert.jsp'">添加新留言</a> </div>
</body>

</html>